// 企业查看简历详情页
import React, {Component} from 'react'
import {ScrollView, View,} from 'react-native';

import {SelResumeInfoComAction} from '../../../actions/resume_c'
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

import Cresume_top from './cresume_top'
import Cresume_basic from './cresume_basic'
import Cresume_experience from './cresume_experience2'
import Cresume_education from './cresume_experience1'
import Cresume_project from './cresume_experience'
import Cresume_intention from './cresume_intention'
import Cresume_oneself from './cresume_oneself1'
import Cresume_attach from './cresume_attach'
import Cresume_skill from './cresume_skill'
import Cresume_button from './cresume_button'
import Loading from '../../../util/loading/loading'

class Cresume_all extends Component {

    // 初始化模拟数据
    constructor(props) {
        super(props);
        this.state = {
            isloading: true
        }
    }

    //加载后渲染页面
    componentDidMount() {
        const {actions} = this.props;
        actions.SelResumeInfoComAction({resumeId: this.props.navigation.state.params.resumeId}); //初始化查询
    }

    componentDidUpdate() {
        if (!this.props.xzResume.isloading && this.state.isloading) {
            this.setState({isloading: false})
        }
    }

    render() {
        const {xzResume} = this.props.xzResume.data;
        if (this.state.isloading) {
            return (
                <Loading/>
                // <View style={{
                //     marginVertical: 10, height: 100, alignItems: 'center', justifyContent: 'flex-end'
                // }}>
                //     <Text>玩命加载ing</Text>
                // </View>
            );
        } else {
            return (
                <View style={{backgroundColor: "#eeeeee"}}>
                    <ScrollView>
                        <Cresume_top navigation={this.props.navigation}/>
                        <Cresume_basic
                            xzResume={xzResume}
                            fields={xzResume.fields}
                            xzResumeEducations={xzResume.xzResumeEducations}
                        />
                        <Cresume_experience
                            xzResume={xzResume}
                            jobExps={xzResume.jobExps}/>
                        <Cresume_education
                            xzResume={xzResume}
                            fields={xzResume.fields}
                            xzResumeEducations={xzResume.xzResumeEducations}
                        />
                        <Cresume_project
                            xzResume={xzResume}
                            xzProjectExps={xzResume.xzProjectExps}
                        />
                        <Cresume_intention
                            xzResume={xzResume}
                            fields={xzResume.fields}
                        />
                        <Cresume_oneself xzResume={xzResume}/>
                        <Cresume_attach xzResume={xzResume}/>
                        <Cresume_skill
                            xzResume={xzResume}
                            xzResumeSkills={xzResume.xzResumeSkills}/>
                        <Cresume_button
                            navigation={this.props.navigation}
                            postionId={this.props.navigation.state.params.postionId}
                            sendId={this.props.navigation.state.params.sendId}
                        />
                    </ScrollView>
                </View>
            )
        }
    }
}

//组合action
let actions = {
    SelResumeInfoComAction
};

//连接state到props
const mapStateToProps = state => {
    return {
        xzResume: state.SelResumeInfoComReducer
    }
};

//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
};

//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(Cresume_all);